<%@page import="com.kaishengit.entity.Prod"%>
<%@page import="com.kaishengit.entity.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="validate.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'main.jsp' starting page</title>
    <script type="text/javascript" src="js/jquery.js"></script>
  </head>
  
  <body>
  	
  
    <h3>Welcome!<%=user.getUsername() %><a href="logout.jsp">安全退出</a></h3>
    <a href="prod.jspx?_m=save">new product</a><a href="shopcar.jsp">我的购物车</a>
    <p></p>
    <table border="1" width="70%">
    	<tr>
    		<th>ID</th>
    		<th>Name</th>
    		<th>Price</th>
    		<th>Action</th>
    	</tr>
 		<c:if test="${fn:length(pager.result)  == 0 }">
 			<tr>
 				<td colspan="4">没有任何商品</td>
 			</tr>
 		</c:if>
    	<c:forEach items="${requestScope.pager.result }" var="p" begin="0" varStatus="prod">
    		<tr>
    		<td>${p.id }</td>
    		<td>${p.prodName }</td>
    		<td>￥${p.price }</td>
    		<td>
    			<a href="addcar.jsp?id=${p.id }">放入购物车</a>
    			<a href="prod.jspx?_m=get&id=${p.id }">edit</a>
    			<a class="del_link" rel="${p.id }" href="javascript:;">delete</a>
    		</td>
    	</tr>
    	</c:forEach>
    </table>
    <a href="prod.jspx?p=${pager.nowPageNum == 1 }">首页</a>
    <c:choose>
    		<c:when test="${pager.nowPageNum == 1 }">
    			上一页
    		</c:when>
    		<c:when test="${pager.nowPageNum !=1 }">
    			<a href="prod.jspx?p=${pager.nowPageNum-1 }">上一页</a>
    		</c:when>
    	</c:choose>
    	<c:choose>
    		<c:when test="${pager.nowPageNum != pager.totalPages }">
    			<a href="prod.jspx?p=${pager.nowPageNum+1 }">下一页</a>
    		</c:when>
    		<c:otherwise>
    			下一页
    		</c:otherwise>
    	</c:choose>
    	<a href="prod.jspx?p=${pager.nowPageNum == pager.totalPages }">尾页</a>
    	
    <script type="text/javascript">
    	$(document).ready(function(){
    		$(".del_link").click(function(){
    			var id = $(this).attr("rel");
    			if(confirm("确定要删除此数据？")) {
					window.location.href = "prod.jspx?_m=del&id=" + id;
    			}
    			
    		});
    		
    	});
    	
    </script>
    
    
  </body>
</html>
